define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    $('#show_putong').hide();
    $('#show_yimiao').hide();
    $('#show_jiuzhen').hide();
    $('#c-typeid').change(function(){
        // 获取选中的值
        var value = $(this).val();
        // 根据选中值显示对应字段
        if(value == 'yimiao'){
            $('#show_putong').hide();
            $('#show_jiuzhen').hide();
            $('#show_yimiao').show();
        }else if(value == 'putong'){
            $('#show_yimiao').hide();
            $('#show_jiuzhen').hide();
            $('#show_putong').show();
        }else{
            $('#show_yimiao').hide();
            $('#show_putong').hide();
            $('#show_jiuzhen').show();
        }
    });
    $('#c-typeid').trigger('change');
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/family_members/index' + location.search,
                    // add_url: 'vppz/bdhospital/add',
                    // edit_url: 'vppz/family_members/edit',
                    // del_url: 'vppz/bdhospital/del',
                    // multi_url: 'vppz/bdhospital/multi',
                    // import_url: 'vppz/bdhospital/import',
                    sendmsg_url: 'vppz/family_members/sendmsg',
                    table: 'vppz_family',
                }
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'name', title: '姓名', operate: 'LIKE'},
                        {field: 'user.mobile', title: '电话', operate: 'LIKE'},
                        {field: 'user.vip_level', title: '会员类型',formatter: function(value, row, index) {
                                const genderMap = {0: '普通会员', 1: '高级会员'};
                                return genderMap[value] || '未知';
                            },
                            // 筛选配置
                            searchList: {
                                '0': '普通会员',
                                '1':'高级会员'
                            },
                            // 筛选操作符（等于）
                            operate: '='},
                        {field: 'age', title: '年龄', // 年龄范围筛选配置
                            operate: 'BETWEEN',  // 表示范围筛选
                            // 自定义筛选控件
                            operateFormatter: function (value, row, index) {
                                return '<input type="number" name="age[min]" placeholder="最小年龄" class="form-control" style="width: 45%; display: inline-block; margin-right: 10%;">' +
                                       '<input type="number" name="age[max]" placeholder="最大年龄" class="form-control" style="width: 45%; display: inline-block;">';
                            }},
                        {field: 'height', title: '身高', // 年龄范围筛选配置
                            operate: 'BETWEEN',  // 表示范围筛选
                            // 自定义筛选控件
                            operateFormatter: function (value, row, index) {
                                return '<input type="number" name="height[min]" placeholder="最低身高" class="form-control" style="width: 45%; display: inline-block; margin-right: 10%;">' +
                                       '<input type="number" name="height[max]" placeholder="最大身高" class="form-control" style="width: 45%; display: inline-block;">';
                            }},
                        {field: 'weight', title: '体重', // 年龄范围筛选配置
                            operate: 'BETWEEN',  // 表示范围筛选
                            // 自定义筛选控件
                            operateFormatter: function (value, row, index) {
                                return '<input type="number" name="weight[min]" placeholder="最小体重" class="form-control" style="width: 45%; display: inline-block; margin-right: 10%;">' +
                                       '<input type="number" name="weight[max]" placeholder="最大体重" class="form-control" style="width: 45%; display: inline-block;">';
                            }},
                        {field: 'blood_types', title: '血型', operate: 'LIKE'},
                        {field: 'gender', title: '性别', // 显示转换：将1/2/3转换为文字
                            formatter: function(value, row, index) {
                                const genderMap = {1: '男', 2: '女', 3: '未知'};
                                return genderMap[value] || '未知';
                            },

                            // 筛选配置
                            searchList: {
                                '1': '男',
                                '2': '女',
                                '3': '未知'
                            },
                            // 筛选操作符（等于）
                            operate: '='},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        //{field: 'admin_id', title: __('Admin_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                    name: 'family',
                                    title: '家人管理',
									text: '家人管理',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/family_manage/index',
                                },{
                                    name: 'detail',
                                    title: '详情',
									text: '详情',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/family_members/detail',
                                }]
						}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },


        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        sendmsg: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
